#pragma once

#include "def_setting.h"

//////////////////////////////////////////////////////////////////////////
//configuration files

#define MAX_SUPPORT_RESOLUTION		3

//AppName
#define APPNAME_DEVICE_INFO			_T("DEVICE_INFO")
#define APPNAME_DEVICE_INFO_EX		_T("DEVICE_INFO_EX")
#define APPNAME_FRONT_CAMERA		_T("FRONT_CAMERA")
#define APPNAME_REAR_CAMERA			_T("REAR_CAMERA")

//#define APPNAME_CAMERA				_T("CAM%02d")
//#define APPNAME_RESOL				_T("CAM%02d_RESOL%d")
//#define APPNAME_AUDIO				_T("AudioControl")



//KeyName
//1. DEVICE_INFO
#define KEYNAME_version				_T("version")
#define KEYNAME_modelName			_T("modelName")
//2. FRONT/REAR_CAMERA
#define KEYNAME_enable				_T("enable")
#define KEYNAME_supportResolution	_T("supportResolution%d")
#define KEYNAME_substreamResolution _T("substreamResolution")
#define KEYNAME_supportSubstream	_T("supportSubstream")
#define KEYNAME_maxFrameRate		_T("maxFrameRate")

#define KEYNAME_mainChip			_T("mainChip")
#define KEYNAME_position			_T("position")
#define KEYNAME_isp					_T("isp")
#define KEYNAME_fpscontrol			_T("fpsControl")
#define KEYNAME_fpsctrl_motion		_T("MotionFpsCtrl")
#define KEYNAME_MainWidth			_T("MainWidth")
#define KEYNAME_MainHeight			_T("MainHeight")
#define KEYNAME_MainFps				_T("MainFps")
#define KEYNAME_MotionFps			_T("MotionFps")
#define KEYNAME_SubEnable			_T("SubEnable")
#define KEYNAME_SubWidth			_T("SubWidth")
#define KEYNAME_SubHeight			_T("SubHeight")
#define KEYNAME_SubFps				_T("SubFps")
#define KEYNAME_MainFps_Sub			_T("MainFps_Sub")
#define KEYNAME_PbEnable			_T("PbEnable")
#define KEYNAME_PbWidth				_T("PbWidth")
#define KEYNAME_PbHeight			_T("PbHeight")
#define KEYNAME_PbFps				_T("PbFps")
#define KEYNAME_MainFps_Pb			_T("MainFps_Pb")
#define KEYNAME_input				_T("input")
#define KEYNAME_output				_T("output")

class CDevConfig
{
public:
	CDevConfig() { Unload(); };
	~CDevConfig() {};

private:
	//DEVICE_INFO
	int m_version;
	TCHAR m_modelName[32];
	int m_mainChip;
	int m_gSensor;
	int m_GPS;
	int m_keyPad;
	int m_liveDisplay;

	//CAMERA
	BOOL m_enable[MAX_CHANNEL];
	int m_sensorType[MAX_CHANNEL];
	int m_width[MAX_CHANNEL];
	int m_height[MAX_CHANNEL];
	int m_maxFrameRate[MAX_CHANNEL];
	int m_supportResolution[MAX_CHANNEL][MAX_SUPPORT_RESOLUTION];
	BOOL m_supportSubstream[MAX_CHANNEL];
	int m_substreamResolution[MAX_CHANNEL];
	int m_subWidth[MAX_CHANNEL];
	int m_subHeight[MAX_CHANNEL];

	BOOL m_bLoad;

public:
	void Load(TCHAR *ptzFileName)
	{
		//DEVICE_INFO
		m_version = GetPrivateProfileInt(APPNAME_DEVICE_INFO, KEYNAME_enable, 100, ptzFileName);
		GetPrivateProfileString(APPNAME_DEVICE_INFO, KEYNAME_modelName, _T(""), m_modelName, sizeof(m_modelName), ptzFileName);

		//CAMERA
		int i, n;
		TCHAR tzSupportResolution[32];
		static TCHAR *tzCamera[MAX_CHANNEL] =
		{
			APPNAME_FRONT_CAMERA,
			APPNAME_REAR_CAMERA
		};
		for (i=0;i<MAX_CHANNEL;i++)
		{
			m_enable[i] = GetPrivateProfileInt(tzCamera[i], KEYNAME_enable, 0,  ptzFileName);
			for (n=0;n<MAX_SUPPORT_RESOLUTION;n++)
			{
				wsprintf(tzSupportResolution, KEYNAME_supportResolution, n);
				m_supportResolution[i][n] = GetPrivateProfileInt(tzCamera[i], tzSupportResolution, 255, ptzFileName);
			}
			m_substreamResolution[i] = GetPrivateProfileInt(tzCamera[i], KEYNAME_substreamResolution, 255, ptzFileName);
			m_supportSubstream[i] = GetPrivateProfileInt(tzCamera[i], KEYNAME_supportSubstream, 0, ptzFileName);
			m_maxFrameRate[i] = GetPrivateProfileInt(tzCamera[i], KEYNAME_maxFrameRate, 30, ptzFileName);

		}
	};

	int version() { return m_version; };
	TCHAR *modelName() { return m_modelName; };

	BOOL enable(int nChannel) { return m_enable[nChannel]; };
	int supportResolution(int nChannel, int nOrder) { return m_supportResolution[nChannel][nOrder]; };
	int supportSubstream(int nChannel) { return m_supportSubstream[nChannel]; };
	int substreamResolution(int nChannel) { return m_substreamResolution[nChannel]; };
	int maxFrameRate(int nChannel) { return m_maxFrameRate[nChannel]; };

	BOOL isLoaded() { return m_bLoad; };
	void Unload() { m_bLoad = FALSE; };



};